package paper.parse;

import paper.parse.HMMatch;
import paper.parse.HMMatcher;
import paper.token.TT;

public class BibliographyParser extends HMMatcher {

    private HMMatch r00  = addState();
    private HMMatch r00a = addState();
    private HMMatch r00b = addState();
    private HMMatch r01  = addState();
    private HMMatch r01a = addState();
    private HMMatch r02  = addState();
    private HMMatch r03  = addState();
    private HMMatch r10a = addState();
    private HMMatch r11a = addState();
    private HMMatch r12a = addState();

    public BibliographyParser(boolean dot, boolean key) {
        if (key) {
            r00.addOut(TT.KEY,     TT.KEY,    r00a);
            
            r10a.addOut(TT.AUTHOR, TT.KEY, r10a);
            r10a.addOut(TT.NUMBER,   TT.NUMBER, r11a);
            r11a.addOut(TT.AUTHOR, TT.AUTHOR, r12a);
            r12a.addOut(TT.AUTHOR, TT.AUTHOR, r12a);
            if(dot) r12a.addOut(TT.DOT,    TT.AUTHOR, r12a);
            r12a.addOut(TT.TITLE,  TT.TITLE, r01);
            
            r00a.addOut(TT.AUTHOR,  TT.KEY,    r10a);
            r00a.addOut(TT.AUTHOR,  TT.AUTHOR, r00b);
            r00b.addOut(TT.AUTHOR,  TT.AUTHOR, r00b);
            if (dot) r00b.addOut(TT.DOT,     TT.AUTHOR, r00b);
            r00b.addOut(TT.NUMBER,  TT.NUMBER, r01a);
            r00b.addOut(TT.TITLE,   TT.TITLE, r01);
        } else {
            r00.addOut( TT.AUTHOR, TT.AUTHOR, r10a);
            r10a.addOut(TT.AUTHOR, TT.AUTHOR, r10a);
            if(dot) {
                r10a.addOut(TT.DOT,    TT.AUTHOR, r10a);
                r10a.addOut(TT.DOT,    TT.NUMBER, r12a);
                r12a.addOut(TT.NUMBER,  TT.NUMBER, r00b);
            } else {
                r10a.addOut(TT.NUMBER,  TT.NUMBER, r00b);
            }
            r00b.addOut(TT.TITLE,   TT.TITLE, r01);
        }
        

        r01a.addOut(TT.TITLE,TT.TITLE, r01);
        r01.addOut(TT.TITLE,TT.TITLE, r01);
        if (dot) r01.addOut(TT.DOT,     TT.EDITOR, r02);
        if (dot) r01.addOut(TT.DOT,     TT.WHERE, r03);
        r01.addOut(TT.AUTHOR,TT.EDITOR, r02);
        r01.addOut(TT.WHERE, TT.WHERE, r03);

        r02.addOut(TT.AUTHOR,  TT.EDITOR, r02);
        if (dot) r02.addOut(TT.DOT,     TT.EDITOR, r02);
        r02.addOut(TT.WHERE,   TT.WHERE,  r03);

        if (dot) r03.addOut(TT.DOT,     TT.WHERE, r03);
        r03.addOut(TT.WHERE,   TT.WHERE, r03);
        r03.addOut(TT.NUMBER,  TT.NUMBER,r03);
        r03.addTerminal();
    }

}